package com.rybbaby.tss.platform.sysFormAttrDictionary.entity;

import org.apache.commons.lang.StringUtils;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.List;

/**
 * @description 表单属性字典
 * 
 * @author 谢进伟
 * 
 * @createDate 2016年2月26日 下午5:59:57
 */
@Entity
@Table(name = "sys_form_attr_dictionary")
@DynamicInsert(value = true)
@DynamicUpdate(value = true)
@SuppressWarnings("serial")
public class SysFormAttrDictionary implements Serializable {
	
	/** 主键 **/
	private String id;
	/** 所属分组Id **/
	private String attrGroupId;
	/** 所属分组 **/
	private SysFormAttrDictionary attrGroup;
	/** 所属分组名 **/
	private String attrGroupName;
	/** 属性名 **/
	private String attrName;
	/** 属性值 **/
	private String attrValue;
	/** 描述 **/
	private String remark;
	/** 权重 **/
	private Integer weight;
	/** 是否只支持HTML5 **/
	private Boolean isOnlySupportHtml5;
	/** 创建时间 **/
	private Timestamp createTime;
	/** 版本 **/
	private Integer version;
	
	/** 表单分组下的所有属性 **/
	private List<SysFormAttrDictionary> childrenFormAttr;
	
	/**
	 * 
	 * 获取主键
	 * 
	 * @return 主键
	 */
	@Id
	@GeneratedValue(generator = "paymentableGenerator" , strategy = GenerationType.AUTO)
	@GenericGenerator(name = "paymentableGenerator" , strategy = "uuid")
	@Column(name = "ID" , nullable = false , length = 32)
	public String getId() {
		return this.id;
	}
	
	/**
	 * 设置主键
	 * 
	 * @param id
	 *            主键
	 */
	public void setId(String id) {
		this.id = id;
	}
	
	/**
	 * 获取属性名
	 * 
	 * @return 属性名
	 */
	@Column(name = "ATTRNAME" , nullable = true , length = 50)
	public String getAttrName() {
		return this.attrName;
	}
	
	/**
	 * 设置属性名
	 * 
	 * @param attrName
	 *            属性名
	 */
	public void setAttrName(String attrName) {
		this.attrName = attrName;
	}
	
	/**
	 * 获取属性值
	 * 
	 * @return attrValue
	 */
	@Column(name = "ATTRVALUE" , nullable = true , length = 65535)
	public String getAttrValue() {
		return this.attrValue;
	}
	
	/**
	 * 设置属性值
	 * 
	 * @param attrValue
	 *            属性值
	 */
	public void setAttrValue(String attrValue) {
		this.attrValue = attrValue;
	}
	
	/**
	 * 获取描述
	 * 
	 * @return 描述
	 */
	@Column(name = "REMARK" , nullable = true , length = 500)
	public String getRemark() {
		return this.remark;
	}
	
	/**
	 * 设置描述
	 * 
	 * @param remark
	 *            描述
	 */
	public void setRemark(String remark) {
		this.remark = remark;
	}
	
	/**
	 * 获取权重
	 * 
	 * @return 权重
	 */
	@Column(name = "WEIGHT" , precision = 11 , scale = 0 , nullable = true)
	public Integer getWeight() {
		return this.weight;
	}
	
	/**
	 * 设置权重
	 * 
	 * @param weight
	 *            权重
	 */
	public void setWeight(Integer weight) {
		this.weight = weight;
	}
	
	/**
	 * 获取是否只支持HTML5
	 * 
	 * @return 是否只支持HTML5
	 */
	@Column(name = "ISONLYSUPPORTHTML5" , precision = 1 , scale = 0 , nullable = true)
	public Boolean getIsOnlySupportHtml5() {
		return this.isOnlySupportHtml5;
	}
	
	/**
	 * 设置是否只支持HTML5
	 * 
	 * @param isOnlySupportHtml5
	 *            是否只支持HTML5
	 */
	public void setIsOnlySupportHtml5(Boolean isOnlySupportHtml5) {
		this.isOnlySupportHtml5 = isOnlySupportHtml5;
	}
	
	/**
	 * 获取创建时间
	 * 
	 * @return 创建时间
	 */
	@Column(name = "CREATETIME")
	public Timestamp getCreateTime() {
		return this.createTime;
	}
	
	/**
	 * 设置创建时间
	 * 
	 * @param createTime
	 *            创建时间
	 */
	public void setCreateTime(Timestamp createTime) {
		this.createTime = createTime;
	}
	
	/**
	 * 获取版本
	 * 
	 * @return 版本
	 */
	@Column(name = "VERSION" , length = 11)
	public Integer getVersion() {
		return this.version;
	}
	
	/**
	 * 设置版本
	 * 
	 * @param version
	 *            版本
	 */
	public void setVersion(Integer version) {
		this.version = version;
	}
	
	/**
	 * 获取表单分组下的所有属性
	 * 
	 * @return 表单分组下的所有属性
	 */
	@OneToMany(cascade = CascadeType.ALL , fetch = FetchType.LAZY , mappedBy = "attrGroup" , targetEntity = SysFormAttrDictionary.class)
	public List<SysFormAttrDictionary> getChildrenFormAttr() {
		return this.childrenFormAttr;
	}
	
	/**
	 * 设置表单分组下的所有属性
	 * 
	 * @param childrenFormAttr
	 *            表单分组下的所有属性
	 */
	public void setChildrenFormAttr(List<SysFormAttrDictionary> childrenFormAttr) {
		this.childrenFormAttr = childrenFormAttr;
	}
	
	/**
	 * 获取所属分组
	 * 
	 * @return 所属分组
	 */
	@JoinColumn(name = "attrGroup" , insertable = false , updatable = false , nullable = true)
	@ManyToOne(fetch = FetchType.LAZY , targetEntity = SysFormAttrDictionary.class)
	public SysFormAttrDictionary getAttrGroup() {
		return this.attrGroup;
	}
	
	/**
	 * 设置所属分组
	 *
	 * @param attrGroup
	 *            所属分组
	 */
	public void setAttrGroup(SysFormAttrDictionary parentAttr) {
		this.attrGroup = parentAttr;
	}
	
	/**
	 * 获取attrGroupName
	 * 
	 * @return attrGroupName
	 */
	@Transient
	public String getAttrGroupName() {
		if(this.attrGroup != null) {
			this.attrGroupName = this.attrGroup.getAttrName();
		}
		return this.attrGroupName;
	}
	
	/**
	 * 获取所属分组Id
	 * 
	 * @return
	 */
	@Column(name = "attrGroup" , nullable = true)
	public String getAttrGroupId() {
		return attrGroupId;
	}
	
	/**
	 * 设置所属分组Id
	 * 
	 * @param attrGroupId
	 */
	public void setAttrGroupId(String attrGroupId) {
		this.attrGroupId = StringUtils.isBlank(attrGroupId) ? null : attrGroupId;
	}
}
